home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8766 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  53 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.netins.net!isac!gg
  3. From: gg@isac.hces.com (Greg Goodrich)
  4. Subject: Re: Using multiple modules
  5. Message-ID: <1996Mar6.001033.3452@isac.hces.com>
  6. Organization: Health Care Expert Systems
  7. X-Newsreader: TIN [version 1.2 PL2]
  8. References: <4h9led$b4g@news.doit.wisc.edu> <4hecka$qf2@hpbblb.bbn.hp.com>
  9. Date: Wed, 6 Mar 1996 00:10:33 GMT
  10.  
  11. matti wrote:
  12. : jdscott@students.wisc.edu (Jim Scott) wrote:
  13. : >I'm trying to break up growing source code into multiple modules.  As 
  14. : >per the FAQ, I've moved all my external definitions to a header file 
  15. : >included in both the modules I'm working with.
  16. : >
  17. : >I can compile the source code into separate object files, but am unable 
  18. : >to link.  I get one of two errors:
  19. : >
  20. : >"symbol defined more than once"  this is in reference to the only 
  21. : >function in the second object file.  I've checked, and it is only 
  22. : >defined in the header file.
  23. : >
  24. : >"unresolved externals"  and a reference to a ??main?? file.  No clue 
  25. : >what's happening here.
  26. : >
  27. : >In the meantime, I'm simply working with the single source file.  Any 
  28. : >help is greatly appreciated!
  29. : >
  30.  
  31. It sounds like you are defining something more than once!  Don't forget
  32. that functions that are in the header file should only be prototypes as
  33. in:
  34.  
  35. extern void do_this();
  36.  
  37. You also should keep in mind that if you declare any variables in a
  38. header, you are bound to have major problems.  You can extern as many
  39. variables as you want, but declare everything in c source files.  This
  40. is probably giving you the trouble, based on your description.  You see,
  41. if you declare something in a header, and 2 source files include this
  42. header, then they both have a declaration of the same variable.  When
  43. you try to link, it trys to resolve all variables and finds two
  44. instances of one or more of them.  This goes for functions as well.
  45. Good luck.
  46.  
  47. Greg.
  48. -- 
  49. _______________________________________
  50.     Greg Goodrich - gg@hces.com
  51.     Software Engineer
  52.     PACE Health Management Systems
  53.